package com.briup.cms.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.cms.domain.Category;
import com.briup.cms.result.Result;
import com.briup.cms.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "栏目管理")
@RestController
@RequestMapping("/auth/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @ApiOperation("查询所有父栏目")
    @GetMapping("/queryAllOneLevel")
    public Result<List<Category>> findAllParent(){
        return Result.success(categoryService.getAllParent());
    }

    @ApiOperation("新增栏目")
    @PostMapping("/save")
    public Result<String> addCategory(@RequestBody Category category){
        categoryService.saveCategory(category);
        return Result.success("新增栏目成功");
    }

    @ApiOperation("根据id查询栏目信息")
    @GetMapping("/getCategoryById/{id}")
    public Result<Category> findCategoryById(@PathVariable Integer id){
        return Result.success(categoryService.getByCategoryId(id));
    }

    @ApiOperation("更新栏目信息")
    @PutMapping("/update")
    public Result<String> editCategoryInfo(@RequestBody Category category){
        return Result.success("更新栏目信息成功");
    }


    @ApiOperation("根据id删除栏目")
    @DeleteMapping("/deleteById/{id}")
    public Result<String> removeCategoryById(@PathVariable Integer id){
        return Result.success("删除成功");
    }

    @ApiOperation("根据ids批量删除栏目")
    @DeleteMapping("/deleteByIdAll/{ids}")
    public Result removeCategoryByIds(@PathVariable List<Integer> ids){
        return Result.success("批量产出成功");
    }

    @ApiOperation("根据parentId条件分页查询所有栏目")
    @GetMapping("/query")
    public Result<IPage<?>> findAllByConditionByPage(@RequestParam Integer pageNum,
                                                     @RequestParam Integer pageSize,
                                                     Integer parentId){
        return Result.success();
    }

    @ApiOperation("查询所有一级栏目及联下属的二级栏目")
    @GetMapping("/queryAllParent")
    public Result findAllParentWithChild(){
        return Result.success();
    }
}
